function getEvent()
{
if(document.all)
{
return window.event;//如果是ie
}
func=getEvent.caller;
while(func!=null)
{
var arg0=func.arguments[0];
if(arg0)
{
if((arg0.constructor==Event || arg0.constructor ==MouseEvent)
||(typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation))
{
return arg0;
}
}
func=func.caller;
}
return null;
}  

function setinputreadonly()
{
	var isshow = $("#isshow").val(); 
	if(isshow=="1")
	{
		$("input[type=text],textarea").each(function(i){
		    $(this).unbind();
		    $(this).bind("focus",function(){this.blur()});
		});
		
	}
}
function closetab(){
	parent.deltab();
}

  //鼠标点击选择行时候变色  
function trchange() {  
   /* var oObj = window.event.srcElement; */ //firex不支持
    var evt=getEvent();
    var oObj=evt.srcElement || evt.target; 
    if(oObj.tagName.toLowerCase() == "td"){     
        var oTr = oObj.parentNode;     
        for(var i=1; i<document.all.thetable.rows.length; i++)   {     
            document.all.thetable.rows[i].style.backgroundColor   =   "";     
            document.all.thetable.rows[i].tag = false;   
        }  
        oTr.style.backgroundColor = "#CCCCFF";     
        oTr.tag = true;     
    }  
}  
//鼠标点击选择行时候变色  
function layuitrchange(obj) {  
        for(var i=1; i<$('.layui-table').find('tbody').children("tr").length; i++)   {     
        	$('.layui-table').find('tbody').children("tr")[i].style.backgroundColor   =   "";     
        	$('.layui-table').find('tbody').children("tr")[i].tag = false;   
        }  
        obj.style.backgroundColor = "#CCCCFF";     
        obj.tag = true;     
}  
//鼠标点击选择行时候变色  
function trchange1() {  
   /* var oObj = window.event.srcElement; */ //firex不支持
    var evt=getEvent();
    var oObj=evt.srcElement || evt.target; 
    if(oObj.tagName.toLowerCase() == "td"){     
        var oTr = oObj.parentNode;     
        for(var i=1; i<document.all.thetableflag.rows.length; i++)   {     
            document.all.thetable1.rows[i].style.backgroundColor   =   "";     
            document.all.thetable1.rows[i].tag = false;   
        }  
        oTr.style.backgroundColor = "#CCCCFF";     
        oTr.tag = true;     
    }  
}  



   //鼠标点击另外一行时关闭已选行变色  
function trout() {  
    var evt=getEvent();
    var oObj=evt.srcElement || evt.target;
    if(oObj.tagName.toLowerCase() == "td"){  
        var oTr = oObj.parentNode;  
        if(!oTr.tag) oTr.style.backgroundColor = "";  
    }  
}  


//鼠标移动到选择行上时的行变色  
function trover(){     
    var evt=getEvent();
    var oObj=evt.srcElement || evt.target;
    if(oObj.tagName.toLowerCase() == "td"){     
    var oTr = oObj.parentNode;  
    if(!oTr.tag) oTr.style.backgroundColor = "#E1E9FD";  
    }  
}  



// map实现  
var map = new Object();  
map.put = function (key,value){  
    var s = "map." + key + ' = "' + value + '";';  
    eval(s);  
}  
map.get = function(key){  
    var v = eval("map." + key + ";");  
    return v;  
}  
  
map.keySet = function(){  
    var keySets = new Array();  
    for(key in map){  
        if(!(typeof(map[key])=="function")){  
            keySets.push(key);  
        }  
    }  
    return keySets;  
}  
//时间配置
var start = {
	elem : '#dateapply',
	format : 'YYYY-MM-DD',
	min : '1970-01-01', // 设定最小日期为当前日期
	max : '2099-06-16', // 最大日期
	istime : true,
	istoday : false,
	choose : function(datas) {
		
	}
};
var dateapply = {
		elem : '#dateapply',
		format : 'YYYY-MM-DD',
		min : '1970-01-01', // 设定最小日期为当前日期
		max : '2099-06-16', // 最大日期
		istime : true,
		istoday : false,
		choose : function(datas) {
			
		}
	};
var reg = "";

function formatred(value, options, rowObject) {
	
	return	"<font size='3' color='red'>"+value+"</font>"	
}
function formatblue(value, options, rowObject) {
	
	return	"<font size='3' color='blue'>"+value+"</font>"	
}
function formatgreen(value, options, rowObject) {
	
	return	"<font size='3' color='green'>"+value+"</font>"	
}
function formatblack(value, options, rowObject) {
	
	return	"<font size='3' color='black'>"+value+"</font>"	
}
//时间列格式化,返回具体的日期
function formatdate(value, row, index) {
	var date = new Date(value).format("yyyy-MM-dd HH:mm:ss");
	if (date == "1970-01-01 00:00:00" || date == "")
		return "--";
	else
		return date;
}

function formattime(value) {
	var date = new Date(value).format("yyyy-MM-dd HH:mm:ss");
	if (date == "1970-01-01 00:00:00" || date == "")
		return "--";
	else
		return date;
}

function getitemcate(value, row, index) {
	if(value=="0")
		return "备品备件";
	if(value=="1")
		return "设备维护";
	if(value=="2")
		return "更新设备";
	if(value=="3")
		return "一次性备品备件";
	return "";
}


function formatdate1(value, row, index) {
	var date = new Date(value).format("yyyy-MM-dd");
	if (date == "1970-01-01" || date == "")
		return "--";
	else
		return date;
}
/*function AntiSqlValid(oField) {
	if ($.trim(oField.value).length <= 0)
		return true;
	if (getByteLen(oField.value) > 40) {
		alertMsgCancel("长度不能超过40个字符或者20个汉字！");
		oField.focus();
		return false;
	}
	var re = /select|update|delete|exec|script|count|'|"|=|;|>|<|%/i;
	if (re.test(oField.value)) {
		alertMsgCancel("请您不要在参数中输入特殊字符和关键字！");
		oField.value = "";
		oField.focus();
		return false;
	}
	return true;
}
function AntiSqlValidlen(oField,len) {
	if ($.trim(oField.value).length <= 0)
		return true;
	if (getByteLen(oField.value) > len) {
		alertMsgCancel("长度不能超过"+len+"字符");
		oField.focus();
		return false;
	}
	var re = /select|update|delete|exec|script|count|'|"|=|;|>|<|%/i;
	if (re.test(oField.value)) {
		alertMsgCancel("请您不要在参数中输入特殊字符和关键字！");
		oField.value = "";
		oField.focus();
		return false;
	}
	return true;
}
function AntiSqlValidnum(oField,num) {
	if ($.trim(oField.value).length <= 0)
		return true;
	if (getByteLen(oField.value) > num) {
		alertMsgCancel("长度不能超过"+num+"字符(汉字减半)!");
		oField.focus();
		return false;
	}
	var re = /select|update|delete|exec|script|count|'|"|=|;|>|<|%/i;
	if (re.test(oField.value)) {
		alertMsgCancel("请您不要在参数中输入特殊字符和关键字！");
		oField.value = "";
		oField.focus();
		return false;
	}
	return true;
}

function getByteLen(val) {
	var len = 0;
	for (var i = 0; i < val.length; i++) {
		var a = val.charAt(i);
		if (a.match(/[^\x00-\xff]/ig) != null) {
			len += 2;
		} else {
			len += 1;
		}
	}
	return len;
}
*/
function checkValidate() {
	var lst = $("input[type='text'],textarea");
	for (var i = 0; i < lst.length; i++) {
		if (!AntiSqlValidlen(lst[i])) {
			return false;
		}
	}
	return true;
}
function AntiSqlValidlen(oField) {
	if (oField.getAttribute("id") == "" || oField.getAttribute("id") == null || oField.getAttribute("id") == undefined
			|| oField.getAttribute("name") == "" || oField.getAttribute("name") == null || oField.getAttribute("name") == undefined) {//针对于layer下拉框
		return true;
	}
	if (oField.getAttribute("datavalidate") == "false" || oField.getAttribute("datavalidate") == undefined) {// 不需要验证
		return true;
	} else {// 需要验证
		
		if($("#"+oField.id).is(":hidden")==true)
			return true;
		
		if (oField.getAttribute("datarequired") == "true") {// 必填
			if ($.trim(oField.value).length <= 0) {
				alertMsgCancel(oField.getAttribute("datatitle") + "不能为空！");
				oField.focus();
				return false;
			}
		}
		

		if ($.trim(oField.value).length <= 0)
			return true;
		if (oField.getAttribute("datatype") != undefined) {// 有类型

			if (oField.getAttribute("datatype") == "mobile") {// 手机号
				if (!(/^1[3|4|5|7|8]\d{9}$/.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "phone") {// 电话号码
				if (!(/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "qq") {// qq号(4-13位)
				if (!(/^\d{4,13}$/.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "email") {// 邮箱
				if (!(/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "url") {// url地址
				var strRegex = '^((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' // ftp的user@
						+ '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL-
						// 199.194.52.184
						+ '|' // 允许IP和DOMAIN（域名）
						+ '([0-9a-z_!~*\'()-]+.)*' // 域名- www.
						+ '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名
						+ '[a-z]{2,6})' // first level domain- .com or .museum
						+ '(:[0-9]{1,4})?' // 端口- :80
						+ '((/?)|' // a slash isn't required if there is no
						// file
						// name
						+ '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$';
				var re = new RegExp(strRegex);
				if (!(re.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "integer") {// 整数类型
				var regu = "^[0-9]*$";
				var re = new RegExp(regu);
				if (!(re.test(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			} else if (oField.getAttribute("datatype") == "number") {// 小数类型
				if (isNaN(Number(oField.value))) {
					alertMsgCancel(oField.getAttribute("datatitle") + "格式不正确！");
					oField.focus();
					return false;
				}
			}
		}
		if (oField.getAttribute("datalength") != undefined) {
			if (oField.value.length > oField.getAttribute("datalength")) {
				alertMsgCancel(oField.getAttribute("datatitle") + "长度不能超过" + oField.getAttribute("datalength") + "字！");
				oField.focus();
				return false;
			}
		}

	/*	var re = /select|update|delete|exec|script|count|'|"|=|;|>|<|%/i;
		if (re.test(oField.value)) {
			alertMsgCancel("请您不要在参数中输入特殊字符和SQL关键字！");
			oField.value = "";
			oField.focus();
			return false;
		}*/
		return true;
	}
}


function getByteLen(val) {
	var len = 0;
	for (var i = 0; i < val.length; i++) {
		var a = val.charAt(i);
		if (a.match(/[^\x00-\xff]/ig) != null) {
			len += 2;
		} else {
			len += 1;
		}
	}
	return len;
}

function qqvalidate(oField,valtitile) {
	if ($.trim(oField.val()).length <= 0)
		return true;
    reg=/^\d{4,15}$/;
	if (!reg.test(oField.val())) {
		alertMsgCancel(valtitile+"为4到15位数字格式！");
		oField.focus();
		return false;
	}
	return true;
}

//验证数字 传值$("$name")
function floatvalidate(oField,valtitile) {
	if ($.trim(oField.val()).length <= 0)
		return true;
	reg =/^\d+(\.\d+)?$/;
	if (!reg.test(oField.val())) {
		alertMsgCancel(valtitile+"为数字格式！");
		
		oField.focus();
		return false;
	}
	if(oField.val().length>12)
	{
		alertMsgCancel(valtitile+"位数太多！");
		oField.focus();
		return false;
	}
	return true;
}

// 验证数字 传值$("$name")
function numvalidate(oField,valtitile) {
	if ($.trim(oField.val()).length <= 0)
		return true;
	reg = new RegExp("^[0-9]*$");
	if (!reg.test(oField.val())) {
		alertMsgCancel(valtitile+"为数字格式！");
		
		oField.focus();
		return false;
	}
	if(oField.val().length>10)
	{
		alertMsgCancel(valtitile+"位数太多！");
		oField.focus();
		return false;
	}
	return true;
}
//验证数字 传值$("$name")
function numvalidateplus(oField,valtitile) {
	if ($.trim(oField.val()).length <= 0)
		return true;
	reg = new RegExp("^[0-9]*$");
	if (!reg.test(oField.val())) {
		alertMsgCancel(valtitile+"为数字格式！");
		
		oField.focus();
		return false;
	}
	if(parseInt(oField.val())<=0)
		{
        alertMsgCancel(valtitile+"应该大于0！");
		oField.focus();
		return false;
		}
	return true;
}
function emailvalidate(oField,valtitile){
	if ($.trim(oField.val()).length <= 0)
		return true;
	reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	 if (reg.test(oField.val())) {
		   return true;
	   } else {
		   alertMsgCancel(valtitile+"邮箱格式不正确！");
	       oField.focus();
	       return false;
	   }
}
function mobilevalidate(oField,valtitile) {
	if ($.trim(oField.val()).length <= 0)
		return true;
	  reg = /^1\d{10}$/;
	   if (reg.test(oField.val())) {
		   return true;
	   } else {
		   reg = /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/;
		   if (reg.test(oField.val())) {
			   return true;
		   } else {
			   alertMsgCancel(valtitile+"格式不正确！");
		       oField.focus();
		       return false;
		   }
	   }
	}
function phonevalidate(oField,valtitile){
	if ($.trim(oField.val()).length <= 0)
		return true;
	reg = /^1\d{10}$|^(0\d{2,3}-?|\(0\d{2,3}\))?[1-9]\d{4,7}(-\d{1,8})?$/;
	 if (reg.test(oField.val())) {
		   return true;
	   } else {
		   reg = /^1\d{10}$/;
		   if (reg.test(oField.val())) {
			   return true;
		   } else {
			   alertMsgCancel(valtitile+"格式不正确！");
		       oField.focus();
		       return false;
		   }
	       return false;
	   }
	}
function Isexitssign(purviewedit,nowdeptid)
{
	var allpur=purviewedit.split(',');
	for(var i=0;i<allpur.length;i++)
	{
		if(allpur[i]==nowdeptid)
			return true;
	}
	  return false;
	
}
function fillid(flag){
	var ids = basejqgrid.jqGrid("getGridParam", "selarrrow");
	if(ids==null||ids.length<=0)
	{
		alertMsgCancel("请选择记录！");
		return false;
	}
	if(flag<2) //增改不是删除
	{
		if(ids.length>1)
		{
			alertMsgCancel("不可以多选记录！");
			return false;
		}
	}
	var allid="";
	var categoriesedit=$("#categoriesedit").val();
	var persinput=$("#persinput").val();
	var purviewedit=$("#purviewedit").val();
	var tid=$("#tid").val();
	for (var i = 0; i < ids.length; i++) { // 清空序号
		if(flag>0)
		{
		if(categoriesedit==3) //编辑本人
		{
			if(basejqgrid.getCell(ids[i], 'persinput')!=persinput)
			{
				alertMsgCancel("对不起,您无权操作！");
				return false;
			}
		}
		if(categoriesedit==2) //编辑本部门
		{
			if(basejqgrid.getCell(ids[i], 'tid')!=tid)
			{
				alertMsgCancel("对不起,您无权操作！");
				return false;
			}
		}
		if(categoriesedit==1) //编辑部分部门
		{
			if(Isexitssign(purviewedit,basejqgrid.getCell(ids[i], 'tid'))==false)
			{
				alertMsgCancel("对不起,您无权操作！");
				return false;
			}
		}
		}
		if(i <ids.length-1)
			allid+=ids[i]+",";
		else
			allid+=ids[i];
	}
	$("#id").val(allid);
	return true;
}

function getcellvalue(rowId, cellId) {
    var cell = $('#' + rowId + '_' + cellId);        
    var val = cell.val();
    return $.trim(val);
}

function setcellvalue(rowId, cellId,value) {
    var cell = $('#' + rowId + '_' + cellId);      
    $('#' + rowId + '_' + cellId).val(value);
}
function fillmergefield(field,num)
{
	var mergevalue="";
	var isexits=false;
	for(var i=1;i<=num;i++)
	{
		//if($("#"+field+i).attr('checked')不行)
		if($("#"+field+i).is(':checked'))
		{
			 isexits=true;
			 mergevalue+= $("#"+field+i).val()+',';
		}
	}
	if(isexits==true)
	{
	    $("#"+field).val(mergevalue.substring(0,mergevalue.length-1));
	}
	else
		 $("#"+field).val("");
}
function fillmergefieldcbo(field)
{
	var mergevalue="";
	var isexits=false;
	var radios = document.getElementsByName("cbo"+field);
    for (i = 0; i < radios.length; i++) {
        if (radios[i].checked) {
        	isexits=true;
        	mergevalue+= radios[i].value+',';
        }
    }
	if(isexits==true)
	{
	    $("#"+field).val(mergevalue.substring(0,mergevalue.length-1));
	}
	else
		 $("#"+field).val("");
}
//时间列格式化,返回具体的日期
function formatgetpicstate(value, row, index) {
	   if (value == '1') return "<font color=#169ADA><span class='glyphicon glyphicon-ok' aria-hidden='true'></span></font>"
       if (value == '0') return "<font color=#169ADA><span class='icon-off' aria-hidden='true'></span></font>";
}
//时间列格式化,返回具体的日期
function formatgetstate(value, row, index) {
	   if (value == '1') return "<font color=#169ADA><span>执行</span></font>"
       if (value == '0') return "<font color=#169ADA><span>未执行</span></font>";
}
//格式化字体大小
/*function addCellAttr(value, row, index) {
    if(value != null ){
    	return "style='size:20px'";
    }
}*/

function addCellAttr(rowId, val, rawObject, cm, rdata) {
    if(rawObject.documentno != null ){
        return "style='font-size:18px'";
    }
}

function clearinputtext()
{
//var els= document.getElementsByTagName("*");   //els得到页面所有控件
var els= document.getElementsByTagName("INPUT"); //上面的也可，这样可以减少循环
for (var i=0;i<els.length;i++ ) 
{
    if (els[i].type == "text") 
    {
        //取得控件ID
    	els[i].value="";
    }
} 
}
function mutiproduct(rowid,numfieldname,pricefieldname,amountfieldname)
{
	var nownum= getcellvalue(rowid, numfieldname);
	var nowprice= getcellvalue(rowid, pricefieldname);
	if(nownum.length>0&&nowprice.length)
	{
		gridlistdetails.jqGrid('setCell',rowid,amountfieldname,(nownum*nowprice).toFixed(2)); 
	}
}


//取消按钮
function winclose() {
	var index = parent.layer.getFrameIndex(window.name);
	parent.layer.close(index);
}
//公共调用方法
function merger(gridName, CellName) {
  //得到显示到界面的id集合
  var mya = $("#" + gridName + "").getDataIDs();
  //当前显示多少条
  var length = mya.length;
  for (var i = 0; i < length; i++) {
      //从上到下获取一条信息
      var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
      //定义合并行数
      var rowSpanTaxCount = 1;
      for (j = i + 1; j <= length; j++) {
          //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
          var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
          if (before[CellName] == end[CellName]) {
              rowSpanTaxCount++;
              $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
          } else {
              rowSpanTaxCount = 1;
              break;
          }
          $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
      }
  }
}


function getsearchsql()
{
	var sql="1=1 ";
	var skind1 = $.trim($(window.frames["frmsearch"].document).find("#skind1").val());
	var nowvalue="";
	if(skind1!="-1")
	{
		var sfield1 = $.trim($(window.frames["frmsearch"].document).find("#sfield1").val());
		if(sfield1.length>0)
		{
			if(skind1=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname1").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield1+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname1").val());
				if(nowvalue.length>0)
				{
					if(skind1=="1") //文字
				     sql+=" and "+sfield1+" ='"+nowvalue+"' ";
					if(skind1=="2") //数字
						  sql+=" and "+sfield1+" ='"+nowvalue+"' ";
				}
			}
		}
	}
	var skind2 = $.trim($(window.frames["frmsearch"].document).find("#skind2").val());
	if(skind2!="-1")
	{
		var sfield2 = $.trim($(window.frames["frmsearch"].document).find("#sfield2").val());
		if(sfield2.length>0)
		{
			if(skind2=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname2").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield2+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname2").val());
				if(nowvalue.length>0)
				{
					if(skind2=="1") //文字
				     sql+=" and "+sfield2+" = '"+nowvalue+"' ";
					if(skind2=="2") //数字
						  sql+=" and "+sfield2+" ='"+nowvalue+"' ";
				}
			}
		}
	}
	var skind3 = $.trim($(window.frames["frmsearch"].document).find("#skind3").val());
	if(skind3!="-1")
	{
		var sfield3 = $.trim($(window.frames["frmsearch"].document).find("#sfield3").val());
		if(sfield3.length>0)
		{
			if(skind3=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname3").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield3+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname3").val());
				if(nowvalue.length>0)
				{
					if(skind3=="1") //文字
				     sql+=" and "+sfield3+" = '"+nowvalue+"' ";
					if(skind3=="2") //数字
						  sql+=" and "+sfield3+" ='"+nowvalue+"' ";
				}
			}
		}
	}
	var skind4 = $.trim($(window.frames["frmsearch"].document).find("#skind4").val());
	if(skind4!="-1")
	{
		var sfield4 = $.trim($(window.frames["frmsearch"].document).find("#sfield4").val());
		if(sfield4.length>0)
		{
			if(skind4=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname4").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield4+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname4").val());
				if(nowvalue.length>0)
				{
					if(skind4=="1") //文字
				     sql+=" and "+sfield4+" = '"+nowvalue+"' ";
					if(skind4=="2") //数字
						  sql+=" and "+sfield4+" ='"+nowvalue+"' ";
				}
			}
		}
	}
	var skind5 = $.trim($(window.frames["frmsearch"].document).find("#skind5").val());
	if(skind5!="-1")
	{
		var sfield5 = $.trim($(window.frames["frmsearch"].document).find("#sfield5").val());
		if(sfield5.length>0)
		{
			if(skind5=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname5").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield5+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname5").val());
				if(nowvalue.length>0)
				{
					if(skind5=="1") //文字
				     sql+=" and "+sfield5+" = '"+nowvalue+"' ";
					if(skind5=="2") //数字
						  sql+=" and "+sfield5+" ='"+nowvalue+"' ";
				}
			}
		}
	}
	var skind6 = $.trim($(window.frames["frmsearch"].document).find("#skind6").val());
	if(skind6!="-1")
	{
		var sfield6 = $.trim($(window.frames["frmsearch"].document).find("#sfield6").val());
		if(sfield6.length>0)
		{
			if(skind6=="0") //下拉框
			{
				nowvalue=$.trim($(window.frames["frmsearch"].document).find("#cbosname6").val());
				if(nowvalue.length>0&&nowvalue!="-1")
				 sql+=" and "+sfield6+"='"+nowvalue+"' ";
			}
			else //输入框
			{
			    nowvalue=$.trim($(window.frames["frmsearch"].document).find("#txtsname6").val());
				if(nowvalue.length>0)
				{
					if(skind6=="1") //文字
				     sql+=" and "+sfield6+" = '"+nowvalue+"' ";
					if(skind6=="2") //数字
						  sql+=" and "+sfield6+" ='"+nowvalue+"' ";
				}
			}
		}
	}
if($("#hchoosetid").val()!="undefined"&&$("#hchoosetid").val()!=null)
{
if($("#hchoosetid").val()==null || $("#hchoosetid").val()=="" || $("#hchoosetid").val()==undefined){
	if($("#hchoosetids").val()=="0"){
		return sql;
	}
	else{
		return sql+" and (id="+$("#hchoosetids").val()+" or id in (select id from topics where fatherid="+$("#hchoosetids").val()+"))";
	}
}else{
	if($("#hchoosetid").val()=="0"){
		return sql;
	}
	else{
		return sql+" and (tid="+$("#hchoosetid").val()+" or tid in (select id from topics where fatherid="+$("#hchoosetid").val()+"))";
	}
}
}
else
	return sql;	
}



//树的参数设置
var setting = {
		    view: {
		        dblClickExpand: false,
		        showLine: true,
		        selectedMulti: false
		    },

		    data: {
		        simpleData: {
		            enable: true,
		            idKey: "id",
		            pIdKey: "pId",
		            rootPId: ""
		        },
		        key: {
		            checked: "tchecked" //checked在C#被占用，需要转义
		        }
		    },
		    callback: {
		        beforeClick: function (treeId, treeNode) {
		        	$("#hchoosetid").val(treeNode.id);
		        	searchform();
		        }
		    }
		};
//绑定树
function bindtopics() {
	$.ajax({
		url : contextPath + '/topics/bindtopics',
		data : {},
		type : 'POST',
		success : function(data) {
			$.fn.zTree.init($("#treetopics"), setting, data);
			//默认完全展开
			/* var treeObj = $.fn.zTree.getZTreeObj("treetopics");
			 treeObj.expandAll(true);*/
		},
		error: function(e) {
			alertMsgCancel(e);
			} 
	});
}

//树的参数设置
var setting1 = {
		    view: {
		        dblClickExpand: false,
		        showLine: true,
		        selectedMulti: false
		    },

		    data: {
		        simpleData: {
		            enable: true,
		            idKey: "id",
		            pIdKey: "pId",
		            rootPId: ""
		        },
		        key: {
		            checked: "tchecked" //checked在C#被占用，需要转义
		        }
		    },
		    callback: {
		        beforeClick: function (treeId, treeNode) {
		        	$("#hchoosetid").val(treeNode.id);
		        	searchform1();
		        }
		    }
		};





//绑定树
function bindtopics1() {
	$.ajax({
		url : contextPath + '/topics/bindtopics',
		data : {},
		type : 'POST',
		success : function(data) {
			$.fn.zTree.init($("#treetopics"), setting1, data);
			//默认完全展开
			/* var treeObj = $.fn.zTree.getZTreeObj("treetopics");
			 treeObj.expandAll(true);*/
		},
		error: function(e) {
			alertMsgCancel(e);
			} 
	});
}

//树的参数设置
var setting2 = {
		    view: {
		        dblClickExpand: false,
		        showLine: true,
		        selectedMulti: false
		    },

		    data: {
		        simpleData: {
		            enable: true,
		            idKey: "id",
		            pIdKey: "pId",
		            rootPId: ""
		        },
		        key: {
		            checked: "tchecked" //checked在C#被占用，需要转义
		        }
		    },
		    callback: {
		        beforeClick: function (treeId, treeNode) {
		        	$("#hchoosetid").val(treeNode.id);
		        	searchform2();
		        }
		    }
		};
//绑定树
function bindtopics2() {
	$.ajax({
		url : contextPath + '/topics/bindtopics',
		data : {},
		type : 'POST',
		success : function(data) {
			$.fn.zTree.init($("#treetopics"), setting2, data);
			//默认完全展开
			/* var treeObj = $.fn.zTree.getZTreeObj("treetopics");
			 treeObj.expandAll(true);*/
		},
		error: function(e) {
			alertMsgCancel(e);
			} 
	});
}


//树的参数设置
var setting3 = {
		    view: {
		        dblClickExpand: false,
		        showLine: true,
		        selectedMulti: false
		    },

		    data: {
		        simpleData: {
		            enable: true,
		            idKey: "id",
		            pIdKey: "pId",
		            rootPId: ""
		        },
		        key: {
		            checked: "tchecked" //checked在C#被占用，需要转义
		        }
		    },
		    callback: {
		        beforeClick: function (treeId, treeNode) {
		        	$("#hchoosetid").val(treeNode.id);
		        	searchform3();
		        }
		    }
		};
//绑定树
function bindtopics3() {
	$.ajax({
		url : contextPath + '/topics/bindtopics',
		data : {},
		type : 'POST',
		success : function(data) {
			$.fn.zTree.init($("#treetopics"), setting3, data);
			//默认完全展开
			/* var treeObj = $.fn.zTree.getZTreeObj("treetopics");
			 treeObj.expandAll(true);*/
		},
		error: function(e) {
			alertMsgCancel(e);
			} 
	});
}

//绑定树
function bindtopics4() {
	$.ajax({
		url : contextPath + '/topics/bindtopics',
		data : {},
		type : 'POST',
		success : function(data) {
			$.fn.zTree.init($("#treetopics"), setting4, data);
			//默认完全展开
			/* var treeObj = $.fn.zTree.getZTreeObj("treetopics");
			 treeObj.expandAll(true);*/
		},
		error: function(e) {
			alertMsgCancel(e);
			} 
	});
}
//课题树的参数设置
var setting4 = {
		    view: {
		        dblClickExpand: false,
		        showLine: true,
		        selectedMulti: false
		    },

		    data: {
		        simpleData: {
		            enable: true,
		            idKey: "id",
		            pIdKey: "pId",
		            rootPId: ""
		        },
		        key: {
		            checked: "tchecked" //checked在C#被占用，需要转义
		        }
		    },
		    callback: {
		        beforeClick: function (treeId, treeNode) {
		        	$("#hchoosetid").val(treeNode.id);
		        	searchform4();
		        }
		    }
		};

function getidchecked()
{
	var idchecked="";
	$('#thetable tbody tr td input[type="checkbox"]').each(function(index, item){
		if(item.checked)
		{
			idchecked+=item.value+','
		}
	});
	if(idchecked.length<=0)
	{
	 
	    alertMsgCancel("请选择列表!");
		return "";
	}
	return idchecked.substr(0,idchecked.length-1);//去掉最后一个逗号
	 
}

function removetrim(obj)
{
	if (!obj || typeof(obj)=="undefined" || obj==0)
	{
		return "";
	}
	return obj;
}

/* 
 * 处理过长的字符串，截取并添加省略号 
 * 注：半角长度为1，全角长度为2 
 *  
 * pStr:字符串 
 * pLen:截取长度 
 *  
 * return: 截取后的字符串 
 */
function autoaddellipsis(pStr, pLen) {

    var _ret = cutString(pStr, pLen);
    var _cutFlag = _ret.cutflag;
    var _cutStringn = _ret.cutstring;

    if ("1" == _cutFlag) {
        return _cutStringn + "...";
    } else {
        return _cutStringn;
    }
}

/* 
 * 取得指定长度的字符串 
 * 注：半角长度为1，全角长度为2 
 *  
 * pStr:字符串 
 * pLen:截取长度 
 *  
 * return: 截取后的字符串 
 */
function cutString(pStr, pLen) {

    // 原字符串长度  
    var _strLen = pStr.length;

    var _tmpCode;

    var _cutString;

    // 默认情况下，返回的字符串是原字符串的一部分  
    var _cutFlag = "1";

    var _lenCount = 0;

    var _ret = false;

    if (_strLen <= pLen / 2) {
        _cutString = pStr;
        _ret = true;
    }

    if (!_ret) {
        for (var i = 0; i < _strLen ; i++) {
            if (isFull(pStr.charAt(i))) {
                _lenCount += 2;
            } else {
                _lenCount += 1;
            }

            if (_lenCount > pLen) {
                _cutString = pStr.substring(0, i);
                _ret = true;
                break;
            } else if (_lenCount == pLen) {
                _cutString = pStr.substring(0, i + 1);
                _ret = true;
                break;
            }
        }
    }

    if (!_ret) {
        _cutString = pStr;
        _ret = true;
    }

    if (_cutString.length == _strLen) {
        _cutFlag = "0";
    }

    return { "cutstring": _cutString, "cutflag": _cutFlag };
}

/* 
 * 判断是否为全角 
 *  
 * pChar:长度为1的字符串 
 * return: true:全角 
 *          false:半角 
 */
function isFull(pChar) {
    if ((pChar.charCodeAt(0) > 128)) {
        return true;
    } else {
        return false;
    }
}


function choosecolor(treeid,name){
	$(treeid).children().each(function(){
        $(this).children("a").css("color","");
        if($(this).children("a").children("cite").text()==name){
                $(this).children("a").css("color","#33AECC");
        }
        $(this).children("ul").children("li").each(function(){
                $(this).children("a").css("color","");
                if($(this).children("a").children("cite").text()==name){
                        $(this).children("a").css("color","#33AECC");
                }
       })
	})
}

function istreeleaf(treeid,name)
{
	var isok=true;
	$(treeid).children().each(function(){
        if($(this).children("a").children("cite").text()==name)
        {
        	/*alert($(this).children("ul").length);
        	alert($(this).children("ul").length<=0);*/
        	isok= $(this).children("ul").length<=0;
  
        }
        $(this).children("ul").children("li").each(function(){
            if($(this).children("a").children("cite").text()==name){
            	/*alert($(this).children("ul").length);
            	alert($(this).children("ul").length<=0);*/
            	isok= $(this).children("ul").length<=0;
        }
   })
  
	})
	return isok;
}
function istreelast(treeid,name)
{
	
	var isok1=false;
	var isok2=false;
	//var isok3=false;
	var count1=0;
	var count2=0;
	var count3=0;
	var nowcount1=0;
	var nowcount2=0;
	//var nowcount3=0;
	try
	{
	$(treeid).children().each(function(){
		count1++;
        if($(this).children("a").children("cite").text()==name)
        {
        	nowcount1=count1;
        }
        count2=0;
        nowcount2=0;
        $(this).children("ul").children("li").each(function(){
        	count2++;
        	
            if($(this).children("a").children("cite").text()==name)
            {
            	nowcount2=count2;
             }
         })
		 if(nowcount2>0)
		{
			 isok2=nowcount2==count2;
		 }
        
     /*   count3=0;
        $(this).children("ul").children("li").children("ul").children("li").each(function(){
        	count3++;
        	//alert($(this).children("a").children("cite").text());
            if($(this).children("a").children("cite").text()==name)
            {
            	nowcount3=count3;
            	//alert(nowcount3=count3);
             }
         })
         if(nowcount3>0)
		{
			 isok3=nowcount3==count3;
		 }*/
	})
	if(nowcount1>0)
	{
		isok1=nowcount1==count1;
	}
	}
	 catch(err) 
	 {
	　　 　　return isok2||isok1;
	　}
	 finally 
	 {
	　　 　 　 　return isok2||isok1;
	　} 
}

/*  只返回目标节点的第一级子节点，具体的用法和getChildren方法是一样的 */
/*$.extend($.fn.tree.methods,{
    getLeafChildren:function(jq, params)
    {
        var nodes = [];
        $(params).next().children().children("div.tree-node").each(function(){
            nodes.push($(jq[0]).tree('getNode',this));
        });
        return nodes;
    }
});*/


var tgs; 
var tmp_background_val; 
function tog(n,flags)
{ 
   //傳過來本次點擊前的的背景顏色 
   if (tgs)
       { 
        tgs.style.background= tmp_background_val ; 
       } 
   //考慮到連續點同一個對象的情況,就不要改變保留的顏色 
 n.style.background= '#99ccff'; 
   if(tgs!=n)
   {
   tmp_background_val=flags;
   tgs=n;
   } 
} 
